public class seekPublicListNode {
    public class Solution {
        public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {
            int count1=0;
            int count2=0;
            ListNode p1=pHead1;
            ListNode p2=pHead2;
            while(p1!=null){
                p1=p1.next;
                count1++;
            }
            while(p2!=null){
                p2=p2.next;
                count2++;
            }
            int count=count1-count2;
            if(count>0){
                for(int i=0;i<count;i++){
                    pHead1=pHead1.next;
                }
            }else{
                count=-count;
                for(int i=0;i<count;i++){
                    pHead2=pHead2.next;
                }
            }
            while(pHead1!=null&&pHead2!=null){
                if(pHead1.val==pHead2.val){
                    return pHead1;
                }
                pHead1=pHead1.next;
                pHead2=pHead2.next;
            }
            return null;
        }
    }
}
